package Tests;

import java.util.Iterator;

import org.jmock.Mockery;
import org.junit.Test;
import junit.framework.Assert;

import Core.Map.CombatGridImpl;
import Core.Map.Tile;
import Core.Character;

public class CombatGridTests
{
	@Test
	public void constructsCorrectNumberOfTiles()
	{
		CombatGridImpl grid = new CombatGridImpl(3, 4, new Tile(0, 0));
		
		Assert.assertEquals(3, grid.rowCount());
		Assert.assertEquals(4, grid.columnCount());
		Assert.assertEquals(12, grid.tiles().size());
	}
	
	@Test
	public void constructsTilesFromDefault()
	{
		Tile originalTile = new Tile(0,0);
		
		CombatGridImpl grid = new CombatGridImpl(1, 3, originalTile);
		
		for (Iterator<Tile> tileIterator = grid.tiles().iterator(); tileIterator.hasNext(); )
		{
			Tile currentTile = tileIterator.next();
			
			Assert.assertNotSame(originalTile, currentTile);
			Assert.assertTrue(originalTile.isSimilarTo(currentTile));
		}
	}
	

	@Test
	public void gridCanFindTileByCharacter()
	{
		Mockery context = new Mockery();
		
		final Character character = context.mock(Character.class);
		
		CombatGridImpl grid = new CombatGridImpl(3, 3, new Tile(0, 0));
		
		Tile originalTile = grid.getTile(1, 2);
		originalTile.addCharacter(character);
		
		Tile foundTile = grid.getTileWithCharacter(character);
		
		Assert.assertSame(originalTile, foundTile);
	}
}
